<template>
  <div class="login-container">
    <div class="login-box">
      <div class="avatar-box">
        <img src="../assets/images/login.jpg" alt="">
      </div>
      <div class="login-form">
        <el-form
          :model="loginForm"
          :rules="loginFormRules"
          ref="loginFormRef"
          label-width="0"
        >
          <el-form-item prop="username">
            <el-input v-model="loginForm.username" placeholder="用户名"></el-input>
          </el-form-item>
          <el-form-item prop="password">
             <el-input v-model="loginForm.password" type="password" placeholder="密码"></el-input>
          </el-form-item>
          <el-form-item class="login-btn">
            <el-button type="primary" @click="login()">登录</el-button>
            <el-button type="info" @click="resetLoginForm()">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'login',
  data () {
    return {
      // 登录表单数据
      loginForm: {
        username: 'admin',
        password: '123456'
      },
      // 数据验证规则
      loginFormRules: {
        // 用户名验证
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    resetLoginForm () {
      this.$refs.loginFormRef.resetFields()
    },
    login () {
      // 先省略登录接口,因为easy-mock挂了,等后台写好了再修改,先把胡乱写的token写入本地
      window.sessionStorage.setItem('token', 'Bearer axtDvMUzP8uUY6vNjHySPyFDkz5Y4V3n')
      window.sessionStorage.setItem('username', 'admin')
      this.$router.push('/home')
    }
  }
}
</script>
<style lang="scss" scoped>
.login-container {
  background: #2b4b6b;
  height: 100%;
  .login-box {
    width: 450px;
    height: 300px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 3px;
    .avatar-box {
      height: 130px;
      width: 130px;
      border: 1px solid #eee;
      border-radius: 50%;
      box-shadow: 0 0 10px #ddd;
      position: absolute;
      left: 50%;
      transform: translate(-50%, -50%);
      background: #fff;
      img {
        width: 100%;
        border-radius: 50%;
      }
    }
    .login-form {
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      padding: 0 15px;
      box-sizing: border-box;
      .login-btn {
        display: flex;
        justify-content: flex-end;
      }
    }
  }
}
</style>
